package Managers;

import Models.User;
import UserView.UserList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Shreyansh
 * Date: 18/8/13
 * Time: 11:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class LoginManager {
    public static boolean isLogged =false;
    public static String userName;
    public void userLogin(UserList userList) {

        String userNameEntered;
        String passwordEntered;
        Scanner getUserName = new Scanner(System.in);
        Scanner getPassword = new Scanner(System.in);
        System.out.println("Enter Username");
        userNameEntered = getUserName.nextLine();
        System.out.println("Enter Password");
        passwordEntered = getPassword.nextLine();
        LoginManager.userName =this.userAuthentication(userNameEntered, passwordEntered,userList);
        if(LoginManager.userName.equals(""))
        {
            System.out.println("Please enter valid Username and Password");
        }
        else{
            isLogged =true;
            System.out.println("Thank You for Logging In");
        }



    }
    public String userAuthentication(String userName, String password,UserList userList)
    {
        //UserList userList=new UserList();
        boolean areDetailsCorrect=false;
        for(User user:userList.obtainList())
        {
            if((user.userName.equals(userName)) && (user.password.equals(password)))
            {
                areDetailsCorrect=true;

                return userName;

            }

        }

        return "";
    }

    public void userLogout() {
        userName ="";
        isLogged =false;
        System.out.println("You have been successfully logged out.");
    }
}
